﻿<!--=================================================================
Copyright (C) Microsoft Corporation.  All rights reserved.
==================================================================-->

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:dg="clr-namespace:ExtendedGrid.Microsoft.Windows.Controls"
                    xmlns:dgp="clr-namespace:ExtendedGrid.Microsoft.Windows.Controls.Primitives">
  <BooleanToVisibilityConverter x:Key="bool2VisibilityConverter" />
  <ControlTemplate x:Key="SelectAllButtonTemplate" TargetType="{x:Type Button}">
    <Grid>
      <Rectangle x:Name="Border"
                 Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" 
                 SnapsToDevicePixels="True" />
      <Polygon x:Name="Arrow"
               HorizontalAlignment="Right"
               VerticalAlignment="Bottom"
               Margin="8,8,3,3"
               Opacity="0.15"
               Fill="Black"
               Stretch="Uniform"
               Points="0,10 10,10 10,0" />
    </Grid>
    <ControlTemplate.Triggers>
      <Trigger Property="IsMouseOver" Value="True">
        <Setter TargetName="Border" Property="Stroke" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" />
      </Trigger>
      <Trigger Property="IsPressed" Value="True">
        <Setter TargetName="Border" Property="Fill" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" />
      </Trigger>
      <Trigger Property="IsEnabled" Value="False">
        <Setter TargetName="Arrow" Property="Visibility" Value="Collapsed" />
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>
  
  <Style x:Key="{x:Type dg:DataGrid}" TargetType="{x:Type dg:DataGrid}">
    <Setter Property="Background"
                Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="BorderBrush" Value="#FF688CAF" />
    <Setter Property="BorderThickness" Value="1" />
    <!-- This is needed to force DG to have a non-default value.  Otherwise the DGR.DetailsVisibility cannot have a value of VisibleWhenSelected by default. -->
    <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected" />
    <Setter Property="ScrollViewer.CanContentScroll"
                Value="true"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type dg:DataGrid}">
          <Border Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  SnapsToDevicePixels="True"
                  Padding="{TemplateBinding Padding}">
            <ScrollViewer   Focusable="false"
                            Name="DG_ScrollViewer">
              <ScrollViewer.Template>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                  <Grid>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="Auto"/>
                      <RowDefinition Height="*"/>
                      <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="Auto"/>
                      <ColumnDefinition Width="*"/>
                      <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <!--Left Column Header Corner -->
                    <Button Command="{x:Static dg:DataGrid.SelectAllCommand}"
                            Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=CellsPanelHorizontalOffset}"
                            Template="{StaticResource SelectAllButtonTemplate}"
                            Focusable="false"
                            Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.All}}" />
                    <!--Column Headers-->
                    <dgp:DataGridColumnHeadersPresenter Grid.Column="1" 
                                                       Name="PART_ColumnHeadersPresenter"
                                                       Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.Column}}"/>

                    <!--DataGrid content-->
                    <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" Grid.Row="1" Grid.ColumnSpan="2" CanContentScroll="{TemplateBinding CanContentScroll}" />

                    <ScrollBar Grid.Row="1" Grid.Column="2" Name="PART_VerticalScrollBar"
                                             Orientation="Vertical"
                                             Maximum="{TemplateBinding ScrollableHeight}"
                                             ViewportSize="{TemplateBinding ViewportHeight}"
                                             Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                             Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>

                    <Grid Grid.Row="2" Grid.Column="1">
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=NonFrozenColumnsViewportHorizontalOffset}"/>
                        <ColumnDefinition Width="*"/>
                      </Grid.ColumnDefinitions>
                      <ScrollBar Grid.Column="1"
                                 Name="PART_HorizontalScrollBar"
                                 Orientation="Horizontal"
                                 Maximum="{TemplateBinding ScrollableWidth}"
                                 ViewportSize="{TemplateBinding ViewportWidth}"
                                 Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                 Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                    
                    </Grid>
                  </Grid>
                </ControlTemplate>
              </ScrollViewer.Template>
              <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </ScrollViewer>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <Trigger Property="IsGrouping" Value="true">
        <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
      </Trigger>
    </Style.Triggers>
  </Style>

  <Style x:Key="{x:Type dgp:DataGridColumnHeadersPresenter}" TargetType="{x:Type dgp:DataGridColumnHeadersPresenter}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type dgp:DataGridColumnHeadersPresenter}">
            <Grid>
                <dgp:DataGridColumnHeader IsHitTestVisible="False" Name="PART_FillerColumnHeader"/>
                <ItemsPresenter />
            </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>


  <Style x:Key="ColumnHeaderGripperStyle" TargetType="{x:Type Thumb}">
    <Setter Property="Width" Value="8"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="Cursor" Value="SizeWE"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Thumb}">
          <Border Padding="{TemplateBinding Padding}"
                    Background="{TemplateBinding Background}"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="RowHeaderGripperStyle" TargetType="{x:Type Thumb}">
    <Setter Property="Height" Value="8"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="Cursor" Value="SizeNS"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Thumb}">
          <Border Padding="{TemplateBinding Padding}"
                  Background="{TemplateBinding Background}"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="{x:Type dgp:DataGridColumnHeader}" TargetType="{x:Type dgp:DataGridColumnHeader}">
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type dgp:DataGridColumnHeader}">
          <Grid>
            <dg:DataGridHeaderBorder SortDirection="{TemplateBinding SortDirection}"
                                     IsHovered="{TemplateBinding IsMouseOver}"
                                     IsPressed="{TemplateBinding IsPressed}"
                                     IsClickable="{TemplateBinding CanUserSort}"
                                     Background="{TemplateBinding Background}"
                                     BorderBrush="{TemplateBinding BorderBrush}"
                                     BorderThickness="{TemplateBinding BorderThickness}"
                                     Padding ="{TemplateBinding Padding}"
                                     SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
                                     SeparatorBrush="{TemplateBinding SeparatorBrush}">
                <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
            </dg:DataGridHeaderBorder>

            <Thumb x:Name="PART_LeftHeaderGripper"
                   HorizontalAlignment="Left"
                   Style="{StaticResource ColumnHeaderGripperStyle}"/>
            <Thumb x:Name="PART_RightHeaderGripper"
                   HorizontalAlignment="Right"
                   Style="{StaticResource ColumnHeaderGripperStyle}"/>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="{x:Type dg:DataGridColumnFloatingHeader}" TargetType="{x:Type dg:DataGridColumnFloatingHeader}">
      <Setter Property="Opacity" Value="0.6"></Setter>
      <Setter Property="BorderBrush" Value="#FF688CAF"></Setter>
      <Setter Property="BorderThickness" Value="1"></Setter>
      <Setter Property="Template">
          <Setter.Value>
              <ControlTemplate TargetType="{x:Type dg:DataGridColumnFloatingHeader}">
                  <Border BorderThickness="{TemplateBinding BorderThickness}"
                          BorderBrush="{TemplateBinding BorderBrush}"
                          Padding ="{TemplateBinding Padding}"
                          Background="{TemplateBinding Background}">
                      <Grid>
                          <Canvas Name="PART_VisualBrushCanvas" Margin="{TemplateBinding Margin}" />
                      </Grid>
                  </Border>
              </ControlTemplate>
          </Setter.Value>
      </Setter>
  </Style>
    
  <Style x:Key="{x:Type dg:DataGridColumnDropSeparator}" TargetType="{x:Type dg:DataGridColumnDropSeparator}">
      <Setter Property="Background" Value="#FF000080" />
      <Setter Property="Template">
          <Setter.Value>
              <ControlTemplate TargetType="{x:Type dg:DataGridColumnDropSeparator}">
                  <Border Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}"
                          BorderThickness="{TemplateBinding BorderThickness}"
                          SnapsToDevicePixels="True">
                  </Border>
              </ControlTemplate>
          </Setter.Value>
      </Setter>
  </Style>
    
  <Style x:Key="{x:Type dg:DataGridRow}" TargetType="{x:Type dg:DataGridRow}">
    <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
    <Setter Property="ValidationErrorTemplate">
      <Setter.Value>
        <ControlTemplate>
          <TextBlock Margin="2,0,0,0" VerticalAlignment="Center" Foreground="Red" Text="!" />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type dg:DataGridRow}">
          <Border x:Name="DGR_Border"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  SnapsToDevicePixels="True">
            <dgp:SelectiveScrollingGrid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
              </Grid.ColumnDefinitions>

              <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
              </Grid.RowDefinitions>

              <dgp:DataGridCellsPresenter Grid.Column="1"
                                         ItemsPanel="{TemplateBinding ItemsPanel}"
                                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

              <dgp:DataGridDetailsPresenter  dgp:SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=AreRowDetailsFrozen, Converter={x:Static dg:DataGrid.RowDetailsScrollingConverter}, ConverterParameter={x:Static dg:SelectiveScrollingOrientation.Vertical}}"
                                            Grid.Column="1" Grid.Row="1"
                                            Visibility="{TemplateBinding DetailsVisibility}" />
              
              <dgp:DataGridRowHeader dgp:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"  Grid.RowSpan="2"
                                    Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.Row}}"/>
            </dgp:SelectiveScrollingGrid>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="{x:Type dgp:DataGridCellsPresenter}" TargetType="{x:Type dgp:DataGridCellsPresenter}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type dgp:DataGridCellsPresenter}">
            <ItemsPresenter />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <SolidColorBrush x:Key="{x:Static dg:DataGrid.FocusBorderBrushKey}" 
                   Color="#FF000000" />

  <Style x:Key="{x:Type dg:DataGridCell}" TargetType="{x:Type dg:DataGridCell}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type dg:DataGridCell}">
          <Border Background="{TemplateBinding Background}" 
                  BorderBrush="{TemplateBinding BorderBrush}"  
                  BorderThickness="{TemplateBinding BorderThickness}" 
                  SnapsToDevicePixels="True">
            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <Trigger Property="IsSelected" Value="True">
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
        <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
      </Trigger>
      <Trigger Property="IsKeyboardFocusWithin" Value="True">
        <Setter Property="BorderBrush" Value="{DynamicResource {x:Static dg:DataGrid.FocusBorderBrushKey}}" />
      </Trigger>
    </Style.Triggers>
  </Style>

  <Style x:Key="{x:Type dgp:DataGridRowHeader}" TargetType="{x:Type dgp:DataGridRowHeader}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type dgp:DataGridRowHeader}">
          <Grid>
            <dg:DataGridHeaderBorder IsSelected="{TemplateBinding IsRowSelected}"
                                     IsHovered ="{TemplateBinding IsMouseOver}"
                                     IsPressed="{TemplateBinding IsPressed}"
                                     Background="{TemplateBinding Background}"
                                     BorderBrush="{TemplateBinding BorderBrush}"
                                     BorderThickness="{TemplateBinding BorderThickness}"
                                     Padding ="{TemplateBinding Padding}"
                                     Orientation="Horizontal"
                                     SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
                                     SeparatorBrush="{TemplateBinding SeparatorBrush}">
              
                <StackPanel Orientation="Horizontal">
                  <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                  <Control SnapsToDevicePixels="false"
                           Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGridRow}}, Path=(Validation.HasError), Converter={StaticResource bool2VisibilityConverter}}"
                           Template="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGridRow}}, Path=ValidationErrorTemplate}" />
                </StackPanel>
            </dg:DataGridHeaderBorder>
            <Thumb x:Name="PART_TopHeaderGripper"
                   VerticalAlignment="Top"
                   Style="{StaticResource RowHeaderGripperStyle}"/>
            <Thumb x:Name="PART_BottomHeaderGripper"
                   VerticalAlignment="Bottom"
                   Style="{StaticResource RowHeaderGripperStyle}"/>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="{x:Type dg:DataGridComboBoxColumn+TextBlockComboBox}" TargetType="{x:Type dg:DataGridComboBoxColumn+TextBlockComboBox}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type dg:DataGridComboBoxColumn+TextBlockComboBox}">
          <ContentPresenter Margin="1,1,1,1"
                            Content="{TemplateBinding SelectionBoxItem}"
                            ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                            ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                            ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            IsHitTestVisible="false" />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>


</ResourceDictionary>
